package com.example.mymvp_2;

import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.example.mymvp_2.Adapter.MyRecyclerViewAdapter;
import com.example.mymvp_2.Base.BaseActivity;
import com.example.mymvp_2.Bean.Channel;
import com.example.mymvp_2.Bean.Weather;
import com.example.mymvp_2.Retrofit02.Presenter.Retrofit2Presenter;
import com.example.mymvp_2.Retrofit02.View.Retrofit2View;

public class Retrofit2Activity extends BaseActivity<Retrofit2Presenter> implements Retrofit2View {
    private static final String TAG = "Retrofit2Activity";
    private RecyclerView recyclerView01;
    private MyRecyclerViewAdapter myRecyclerViewAdapter;

    @Override
    public int getLayout() {
        return R.layout.activity_retrofit2;
    }

    @Override
    public void initView() {
        recyclerView01=findViewById(R.id.recyclerView);
    }

    @Override
    public void initData() {
        mPresenter=new Retrofit2Presenter(this);
        UpdateWeather();
    }

    @Override
    public void onRetrofitSuccess(Weather weather) {
        myRecyclerViewAdapter = new MyRecyclerViewAdapter(this,weather);
        recyclerView01.setAdapter(myRecyclerViewAdapter);
    }

    @Override
    public void onRetrofitError(String errMessage) {
        Toast.makeText(this, errMessage, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRetrofitPostSuccess(String msg) {
        Toast.makeText(this, "post请求成功"+msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onRetrofitXMLSuccess(Channel channel) {
        Log.e(TAG, "onRetrofitXMLSuccess: "+channel.getTitle() );
    }


    public void Retrofit01(View view) {
        UpdateWeather();//更新天气
//        UpdateWeather02PostNews();post请求  @post
//        mPresenter.XMLRetrofit();xml解析 SimpleXml
    }

    private void UpdateWeather() {
        if (hasPermission) {
            mPresenter.getRetrofit2();
        }else {
            ShowAlertWhyGetPermissions("请先开启权限再使用,权限用于获取当前城市以提供更精准的天气服务");
        }
    }

    private void UpdateWeather02PostNews(){
        mPresenter.Post();
    }

}
